package net.caixiaomi.info.adapter;

import android.support.annotation.LayoutRes;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.TextView;

import net.caixiaomi.info.R;
import net.caixiaomi.info.app.CommonApp;
import net.caixiaomi.info.base.quickadapter.BaseQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.model.PrintTicketItem;

/**
 * 出票方案
 */

public class PrintTicketPlanAdapter extends BaseQuickAdapter<PrintTicketItem, BaseViewHolder> {

    public PrintTicketPlanAdapter(@LayoutRes int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, PrintTicketItem item) {
        try {
            helper.itemView.setPadding((int) CommonApp.getInstance().getResources().getDimension(net.caixiaomi.info.R.dimen.padding_12), 0, (int) CommonApp.getInstance().getResources().getDimension(net.caixiaomi.info.R.dimen.padding_12), 0);
            helper.setVisible(net.caixiaomi.info.R.id.line, (helper.getAdapterPosition() - getHeaderLayoutCount()) != (getData().size() - 1));

            StringBuilder stringBuilder = new StringBuilder();
            String[] xes = item.getTickeContent().split("X");
            for (int index = 0; index < xes.length; index++) {
                stringBuilder.append(xes[index].trim());
                if (index != xes.length - 1) {
                    stringBuilder.append("X").append("\n");
                }
            }
            helper.setText(net.caixiaomi.info.R.id.name, stringBuilder);
            TextView view = helper.getView(net.caixiaomi.info.R.id.name);
            view.setGravity(Gravity.LEFT);
            helper.setTextColor(net.caixiaomi.info.R.id.name, ContextCompat.getColor(CommonApp.getInstance(), net.caixiaomi.info.R.color.primary_text));
            helper.setText(net.caixiaomi.info.R.id.way, item.getPassType());
            helper.setTextColor(net.caixiaomi.info.R.id.way, ContextCompat.getColor(CommonApp.getInstance(), net.caixiaomi.info.R.color.primary_text));
            helper.setText(net.caixiaomi.info.R.id.treble, item.getMultiple());
            helper.setTextColor(net.caixiaomi.info.R.id.treble, ContextCompat.getColor(CommonApp.getInstance(), net.caixiaomi.info.R.color.primary_text));
            String status = CommonApp.getInstance().getString(R.string.C_WAIT_PRINT_TICKET);
            if (TextUtils.equals(item.getStatus(), "1")) {
                status = CommonApp.getInstance().getString(R.string.C_HAS_PRINT_TICKET);
            } else if (TextUtils.equals(item.getStatus(), "2")) {
                status = CommonApp.getInstance().getString(R.string.C_PRINT_TICKET_FAIL);
            } else if (TextUtils.equals(item.getStatus(), "3")) {
                status = CommonApp.getInstance().getString(R.string.C_PRINT_TICKET_ING);
            }
            helper.setText(net.caixiaomi.info.R.id.status, status);
            helper.setTextColor(net.caixiaomi.info.R.id.status, ContextCompat.getColor(CommonApp.getInstance(), net.caixiaomi.info.R.color.orange_primary));


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
